package com.efuture.redis.findprovicedemo.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.InputStream;
import java.util.Properties;

/**
 * @author ：赵山山
 * @description：Jedis连接池工具类编写
 * @date ：2021/10/5 10:52 下午
 */
public class JedisPoolUtils {

    private static JedisPool jedisPool;
    static {
       try{
           Properties properties = new Properties();
           InputStream is = JedisPoolUtils.class.getClassLoader().getResourceAsStream("jedis.properties");
           properties.load(is);
           JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
           jedisPoolConfig.setMaxTotal(Integer.parseInt(properties.getProperty("maxTotal")));
           jedisPoolConfig.setMaxIdle(Integer.parseInt(properties.getProperty("maxIdle")));
           jedisPool = new JedisPool(jedisPoolConfig,properties.getProperty("host"),Integer.parseInt(properties.getProperty("port")));
       }catch (Exception e){
           e.printStackTrace();
       }
    }


    public static Jedis getJedis(){
        return jedisPool.getResource();
    }
}

